<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/public.css">
</head>

<body>
    <!-- textAlign  根据锚点，设置或返回文本内容的当前对齐方式 -->

    <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"></canvas>

    <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");

        // 在位置 150 创建蓝线
        ctx.strokeStyle = "blue";
        ctx.moveTo(150, 20);
        ctx.lineTo(150, 170);
        ctx.stroke();
        ctx.font = "15px Arial";

        // 显示不同的 textAlign 值
        ctx.textAlign = "start";
        ctx.fillText("textAlign=start", 150, 60);
        ctx.textAlign = "end";
        ctx.fillText("textAlign=end", 150, 80);
        ctx.textAlign = "left";
        ctx.fillText("textAlign=left", 150, 100);
        ctx.textAlign = "center";
        ctx.fillText("textAlign=center", 150, 120);
        ctx.textAlign = "right";
        ctx.fillText("textAlign=right", 150, 140);
    </script>
</body>

</html>